package org.sunflower.util.thread;

import java.util.concurrent.Callable;

public class TreadHandle implements Callable<String>{
	int forId = 0;
	String threadPoolType;
	static int sForId = 0;
	static String sThreadPoolType;
	static TreadHandle treadHandle;
	public TreadHandle(){}
	public TreadHandle(int id,String type){
		this.forId = id;
		this.threadPoolType = type;
	}
	//单例
	public static TreadHandle getTreadHandle(int id,String type){
		if(treadHandle==null){
			treadHandle = new TreadHandle();
		}
		sForId = id;
		sThreadPoolType = type;
		return treadHandle;
	}
	
	public static void taskRun(int forId,String threadPoolType){
		Thread currentThread = Thread.currentThread();
		System.out.println(String.format("耗时程序（线程类名：%s，线程名称%s，线程Id:%s,循环编号：%s）",threadPoolType, currentThread.getName(),currentThread.getId(),forId));
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} 
	@Override
	public String call() throws Exception {
		taskRun(forId,threadPoolType);
		Thread currentThread = Thread.currentThread();
		return String.format("返回结果（线程类名：%s，线程名称%s，线程Id:%s,循环编号：%s）",threadPoolType,currentThread.getName(),currentThread.getId(),forId);
	}

}
